/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fileman;

import NodeManager.ManagedFile;
import NodeManager.RdfModelManager;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.DefaultListModel;
import javax.swing.ListModel;
import java.io.File;
import java.util.Vector;

/**
 *
 * @author Murhaf
 */
public class ViewCreator {

    public static DefaultListModel getFiles(Object modelManager, Object nodeName) {
        DefaultListModel listModel = new DefaultListModel();
        if (nodeName == null) {
            return listModel;
        }

        RdfModelManager model = (RdfModelManager) modelManager;
        Vector<ManagedFile> managedFiles  = model.GetAllManagedFiles((String) nodeName);
        for (ManagedFile managedFile : managedFiles) {
            listModel.addElement(managedFile.FileName);
        }

        return listModel;

    }

    public static ArrayList getFoldersAsList() {

        ArrayList folders = new ArrayList();
        String path = Global.Data.NodesDirectory;
        File folder = new File(path);

        for (File subFolder : folder.listFiles()) {
            if (subFolder.isDirectory()) {
                folders.add(subFolder.getName());
            }
        }
        return folders;
    }

    public static ArrayList getFilesAsList(
            String path) {

        ArrayList files = new ArrayList();

        path = Global.Data.NodesDirectory + File.separatorChar + path + File.separatorChar;

        File folder = new File(path);
        File[] listOfFiles = folder.listFiles();

        for (File file : folder.listFiles()) {
            if (file.isFile()) {
                files.add(file.getName());
            }
        }
        return files;
    }
}
